﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Windows.Forms;
using BusinessObjects;
using DataAccess;

namespace QuanLyHopDong
{
    public partial class NgachLuongDetailView : Form
    {
        public event EventHandler SaveChanged;
        public event EventHandler DeleteChanged;

        BindingList<NgachLuong> bingdingListNgachLuong;
        private NgachLuong _ngachLuong;

        public NgachLuongDetailView()
        {
            InitializeComponent();
        }
        public NgachLuongDetailView(NgachLuong ngachLuong)
        {
            InitializeComponent();

            _ngachLuong = ngachLuong;
            bingdingListNgachLuong = new BindingList<NgachLuong>();
            bingdingListNgachLuong.Add(_ngachLuong);

            bindingSourceNgachLuong.DataSource = bingdingListNgachLuong;
        }

        private void btnLuu_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Luu();
        }
        private void LuuVaDong_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Luu();
            this.Close();
        }

        private void btnDong_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.Close();
        }

        private void btnXoa_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
        }

        void Luu()
        {
            if (_ngachLuong.Oid == -1)
            {
                DataAccessObject.NgachLuong.Insert(_ngachLuong);
                OnSaveChange();
            }
            else
                DataAccessObject.NgachLuong.Update(_ngachLuong);
        }
        void OnSaveChange()
        {
            if (SaveChanged != null)
            {
                SaveChanged(this, EventArgs.Empty);
            }
        }
    }
}
